//---------------highcharts---------------------
function rendererPieChart(data, container, title) {
	if(!title) title = "资产分布图";
	Highcharts.chart(container, {
	    chart: {
	        plotBackgroundColor: null,
	        plotBorderWidth: null,
	        plotShadow: false,
	        type: 'pie'
	    },
	    title: {
	        text: title
	    },
	    tooltip: {
	        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
	    },
	    plotOptions: {
	        pie: {
	            allowPointSelect: true,
	            cursor: 'pointer',
	            dataLabels: {
	                enabled: true,
	                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
	                style: {
	                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
	                }
	            }
	        }
	    },
	    series: [{
	        name: '资产份额',
	        colorByPoint: true,
	        data: data
	    }]
	});

}

function rendererAreaChart(categories, data, container, title, subtitle) {
	if(!title) title = '资产成本/市值图';
	if(!subtitle) subtitle = '周期成本/市值分析表(周)';
	Highcharts.chart(container, {
	    chart: {
	        type: 'areaspline'
	    },
	    title: {
	        text: title
	    },
        subtitle: {
            text: subtitle
        },
	    legend: {
            layout: 'vertical',
            align: 'left',
            x: 0,
            verticalAlign: 'top',
            y: 0,
            floating: true,
            backgroundColor: '#FFFFFF'
	    },
	    xAxis: {
	        categories: categories,
	        plotBands: [{ // visualize the weekend
	            from: 4.5,
	            to: 6.5,
	            color: 'rgba(168, 170, 213, .5)'
	        }]
	    },
	    yAxis: {
	        title: {
	            text: '资产'
	        }
	    },
	    tooltip: {
	        shared: true,
	        valueSuffix: ' ￥'
	    },
	    credits: {
	        enabled: false
	    },
	    plotOptions: {
			spline: {
				lineWidth: 2,
				states: {
					hover: {
						lineWidth: 3
					}
				},
			marker: {
				enabled: false
			}
		}
	    },
	    series: data
	});	
}

function showAssetsPriceChart(categories, data, container, props) {
	if(!props) props = {};
	if(!props.title) props.title = '利润分析表';
	if(!props.subtitle) props.subtitle = '周期利润/利润率分析表(周)';
	if(!props.yAxis_title1) props.yAxis_title1 = '利润 (元)';
	Highcharts.chart(container, {
        chart: {
            renderTo: container,          //放置图表的容器
            plotBackgroundColor: null,
            plotBorderWidth: null,
            zoomType: 'xy' //支持图表放大缩小的范围
        },
        title: {
            text: props.title
        },
        subtitle: {
            text: props.subtitle
        },
        xAxis: [{
            categories: categories,
            labels: {
                rotation: -45, //字体倾斜
                align: 'right',
                style: { font: 'normal 13px 宋体' }
            }
        }],
        yAxis: [{ // Primary yAxis
            title: {
                text: props.yAxis_title1,
                style: {
                    color: '#89A54E'
                }
            },
            labels: {
                format: '{value} 元',//格式化Y轴刻度
                style: {
                    color: '#89A54E'
                }
            }
        }],
        tooltip: {
            shared: true, //公用一个提示框
            formatter: function() {
                return this.x +"<br>"
                   + "<span style='color:#4572A7'>价格：" + this.points[0].y +" 元</span><br>" 
                ;
            }
        },
	    plotOptions: {
			spline: {
				lineWidth: 1,
				states: {
					hover: {
						lineWidth: 2
					}
				},
			marker: {
				enabled: false
			}
		}
	    },
        //图例样式设置
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 0,
            verticalAlign: 'top',
            y: 0,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series: data
	});	
}

function rendererProfitChart(categories, data, container, props) {
	if(!props) props = {};
	if(!props.title) props.title = '利润分析表';
	if(!props.subtitle) props.subtitle = '周期利润/利润率分析表(周)';
	if(!props.yAxis_title1) props.yAxis_title1 = '利润 (元)';
	if(!props.yAxis_title2) props.yAxis_title2 = '利润率 (%)';
	Highcharts.chart(container, {
        chart: {
            renderTo: container,          //放置图表的容器
            plotBackgroundColor: null,
            plotBorderWidth: null,
            zoomType: 'xy' //支持图表放大缩小的范围
        },
        title: {
            text: props.title
        },
        subtitle: {
            text: props.subtitle
        },
        xAxis: [{
            categories: categories,
            labels: {
                rotation: -45, //字体倾斜
                align: 'right',
                style: { font: 'normal 13px 宋体' }
            }
        }],
        yAxis: [{ // Primary yAxis
            title: {
                text: props.yAxis_title1,
                style: {
                    color: '#89A54E'
                }
            },
            labels: {
                format: '{value} 元',//格式化Y轴刻度
                style: {
                    color: '#89A54E'
                }
            }
        }, {
            title: {
                text: props.yAxis_title2,
                style: {
                    color: '#4572A7'
                }
            },
            labels: {
                format: '{value} 元',
                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
        tooltip: {
            shared: true, //公用一个提示框
            formatter: function() {
                return this.x +"<br>"
                   + "<span style='color:#4572A7'>利润：" + this.points[0].y +" 元</span><br>" 
                   + "<span style='color:#89A54E'>利润率：" + this.points[1].y +" %</span>"
                ;
            }
        },
	    plotOptions: {
			spline: {
				lineWidth: 2,
				states: {
					hover: {
						lineWidth: 3
					}
				},
			marker: {
				enabled: false
			}
		}
	    },
        //图例样式设置
        legend: {
            layout: 'vertical',
            align: 'left',
            x: 0,
            verticalAlign: 'top',
            y: 0,
            floating: true,
            backgroundColor: '#FFFFFF'
        },
        series2: [{
            name: '发送数',
            color: '#4572A7',
            type: 'column',
            yAxis: 1,
            data: [50, 70, 100, 120, 145, 176, 135],
            tooltip: {
                formatter: function() {
                    return this.y +"条";
                }
            }

        }, {
            name: '成功率',
            color: '#89A54E',
            type: 'spline',
            yAxis: 0,
            data: [80, 22.5, 45, 90, 99, 35, 45 ],
            tooltip: {
                valueSuffix: ' %'
            }
        }],
        series: data
	});	
}


function rendererProfitChart2(categories, data, container, props) {
	if(!props) props = {};
	if(!props.title) props.title = '利润分析表';
	if(!props.subtitle) props.subtitle = '周期利润/利润率分析表(周)';
	if(!props.yAxis_title1) props.yAxis_title1 = '利润 (元)';
	if(!props.yAxis_title2) props.yAxis_title2 = '利润率 (%)';
	Highcharts.chart(container, {
		chart: {
			type: 'spline'
		},
        title: {
            text: props.title
        },
        subtitle: {
            text: props.subtitle
        },
        xAxis: [{
            categories: categories,
            labels: {
                rotation: -45, //字体倾斜
                align: 'right',
                style: { font: 'normal 13px 宋体' }
            }
        }],
        yAxis: [{ // Primary yAxis
            title: {
                text: props.yAxis_title1,
                style: {
                    color: '#89A54E'
                }
            },
            labels: {
                format: '{value} 元',//格式化Y轴刻度
                style: {
                    color: '#89A54E'
                }
            }
        }, {
            title: {
                text: props.yAxis_title2,
                style: {
                    color: '#4572A7'
                }
            },
            labels: {
                format: '{value} ',
                style: {
                    color: '#4572A7'
                }
            },
            opposite: true
        }],
        tooltip: {
            shared: true, //公用一个提示框
            formatter: function() {
            	if(this.points[2].y == 0 && this.points[3].y == 0) return "没有交易";
            	if(this.points[2].y > 0) {
                    return this.x +"<br>"
                    + "<span style='color:#89A54E'>成本价：" + this.points[0].y +" 元</span><br>"
                    + "<span style='color:#FF0000'>买入价：" + this.points[1].y +" 元</span><br>" 
                    + "<span style='color:#89A54E'>买入量：" + this.points[2].y +" </span><br>" ;
            	} else {
                    return this.x +"<br>"
                    + "<span style='color:#89A54E'>成本价：" + this.points[0].y +" 元</span><br>"
                    + "<span style='color:#0000FF'>卖出价：" + this.points[1].y +" 元</span><br>" 
                    + "<span style='color:#89A54E'>卖出量：" + this.points[3].y +" </span><br>" ;
            	}
            }
        },
	    plotOptions: {
	    	series: {
	    		marker: {
	    			radius: 3,
	    			symbol: 'circle'   //曲线点类型：”circle”, “square”, “diamond”, “triangle”,”triangle-down”
	    		}
	    	},
			spline: {
				lineWidth: 2,
				states: {
					hover: {
						lineWidth: 3
					}
				},
			marker: {
				enabled: false
			}
		}
	    },
	    series: data
	});	
}